unit uOpenGL;

interface

type
  TGLint      = Integer;
	TGLsizei    = Integer;
  TGLubyte    = Byte;
	TGLuint     = Cardinal;
  TGLenum     = Cardinal;
  TGLbitfield = Cardinal;
	TGLfloat    = Single;
  TGLdouble   = Double;
  TGLclampf   = Single;

  PGLubyte    = ^TGLubyte;
  PGLuint     = ^TGLuint;
  PGLvoid     = Pointer;

const
{$IFDEF WIN32}
  OpenGLLib = 'OpenGL32.dll';
{$ELSE}
  OpenGLLib = 'libGL.so';
{$ENDIF}

	GL_COLOR_BUFFER_BIT     = $00004000;
	GL_POINTS               = $0000;
  GL_LINES                = $0001;
  GL_LINE_STRIP           = $0003;
  GL_TRIANGLES            = $0004;
  GL_TRIANGLE_STRIP       = $0005;
  GL_TRIANGLE_FAN         = $0006;
  GL_QUADS                = $0007;
	GL_SRC_ALPHA            = $0302;
  GL_ONE_MINUS_SRC_ALPHA  = $0303;
	GL_UNSIGNED_BYTE        = $1401;
	GL_BLEND                = $0BE2;
	GL_UNPACK_ALIGNMENT     = $0CF5;
	GL_TEXTURE_2D           = $0DE1;
	GL_MODELVIEW            = $1700;
  GL_PROJECTION           = $1701;
	GL_ALPHA                = $1906;
  GL_RGB                  = $1907;
  GL_RGBA                 = $1908;
	GL_EXTENSIONS           = $1F03;
	GL_MODULATE             = $2100;
  GL_TEXTURE_ENV_MODE     = $2200;
	GL_TEXTURE_ENV          = $2300;
	GL_NEAREST              = $2600;
  GL_LINEAR               = $2601;
	GL_TEXTURE_MAG_FILTER   = $2800;
  GL_TEXTURE_MIN_FILTER   = $2801;
  GL_TEXTURE_WRAP_S       = $2802;
  GL_TEXTURE_WRAP_T       = $2803;
  GL_CLAMP                = $2900;
  GL_REPEAT               = $2901;
	GL_CLAMP_TO_BORDER_SGIS = $812D;

var
	glBegin: procedure(mode: TGLenum); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glBindTexture: procedure(target: TGLenum; texture: TGLuint); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glBlendFunc: procedure(sfactor: TGLenum; dfactor: TGLenum); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glClear: procedure(mask: TGLbitfield); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glClearColor: procedure(red: TGLclampf; green: TGLclampf; blue: TGLclampf; alpha: TGLclampf); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glColor4ub: procedure(red: TGLubyte; green: TGLubyte; blue: TGLubyte; alpha: TGLubyte); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glDeleteTextures: procedure(n: TGLsizei; const textures: PGLuint); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glDisable: procedure(cap: TGLenum); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glEnable: procedure(cap: TGLenum); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glEnd: procedure(); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glFlush: procedure(); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glGenTextures: procedure(n: TGLsizei; textures: PGLuint); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glGetString: function(name: TGLenum): PChar; {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glGetTexImage: procedure(target: TGLenum; level: TGLint; format: TGLenum; _type: TGLenum; pixels: PGLvoid); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glLoadIdentity: procedure(); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glMatrixMode: procedure(mode: TGLenum); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glOrtho: procedure(left: TGLdouble; right: TGLdouble; bottom: TGLdouble; top: TGLdouble; zNear: TGLdouble; zFar: TGLdouble); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glPixelStorei: procedure(pname: TGLenum; param: TGLint); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glPopMatrix: procedure(); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glPushMatrix: procedure(); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glRotatef: procedure(angle: TGLfloat; x: TGLfloat; y: TGLfloat; z: TGLfloat); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glScalef: procedure(x: TGLfloat; y: TGLfloat; z: TGLfloat); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glTexCoord2f: procedure(s: TGLfloat; t: TGLfloat); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glTexEnvi: procedure(target: TGLenum; pname: TGLenum; param: TGLint); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glTexImage2D: procedure(target: TGLenum; level: TGLint; internalformat: TGLint; width: TGLsizei; height: TGLsizei; border: TGLint; format: TGLenum; _type: TGLenum; const pixels: PGLvoid); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glTexParameteri: procedure(target: TGLenum; pname: TGLenum; param: TGLint); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glTranslatef: procedure(x: TGLfloat; y: TGLfloat; z: TGLfloat); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}
  glVertex2f: procedure(x: TGLfloat; y: TGLfloat); {$IFDEF WIN32}stdcall;{$ELSE}cdecl;{$ENDIF}

function InitOpenGL(libName: String = OpenGLLib): Boolean;

implementation

uses
  uLib;

function InitOpenGL(libName: String = OpenGLLib): Boolean;
var
  lib: Cardinal;
begin
  Result := False;

  lib := LibOpen(libName);

  if lib <> 0 then
  begin
    glBegin := LibProc(lib, 'glBegin');
    glBindTexture := LibProc(lib, 'glBindTexture');
    glBlendFunc := LibProc(lib, 'glBlendFunc');
    glClear := LibProc(lib, 'glClear');
    glClearColor := LibProc(lib, 'glClearColor');
    glColor4ub := LibProc(lib, 'glColor4ub');
    glDeleteTextures := LibProc(lib, 'glDeleteTextures');
    glDisable := LibProc(lib, 'glDisable');
    glEnable := LibProc(lib, 'glEnable');
    glEnd := LibProc(lib, 'glEnd');
    glFlush := LibProc(lib, 'glFlush');
    glGenTextures := LibProc(lib, 'glGenTextures');
    glGetString := LibProc(lib, 'glGetString');
    glGetTexImage := LibProc(lib, 'glGetTexImage');
    glLoadIdentity := LibProc(lib, 'glLoadIdentity');
    glMatrixMode := LibProc(lib, 'glMatrixMode');
    glOrtho := LibProc(lib, 'glOrtho');
    glPixelStorei := LibProc(lib, 'glPixelStorei');
    glPopMatrix := LibProc(lib, 'glPopMatrix');
    glPushMatrix := LibProc(lib, 'glPushMatrix');
    glRotatef := LibProc(lib, 'glRotatef');
    glScalef := LibProc(lib, 'glScalef');
    glTexCoord2f := LibProc(lib, 'glTexCoord2f');
    glTexEnvi := LibProc(lib, 'glTexEnvi');
    glTexImage2D := LibProc(lib, 'glTexImage2D');
    glTexParameteri := LibProc(lib, 'glTexParameteri');
    glTranslatef := LibProc(lib, 'glTranslatef');
    glVertex2f := LibProc(lib, 'glVertex2f');

    Result := True;
  end;
end;

initialization
  Set8087CW($133F);
end.
